package com.dlc.shop.api.config;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author FrozenWatermelon
 * @date 2020/12/15
 */
@Configuration
@EnableConfigurationProperties(ThreadPoolConfigProperties.class)
public class OrderThreadConfig {

    /**
     * 因为每台机器不同，所以线程数量应该是通过配置文件进行配置的
     * @param pool 线程池配置信息
     * @return 订单线程池
     */
    @Bean
    public ThreadPoolExecutor orderThreadPoolExecutor(ThreadPoolConfigProperties pool) {
        return new ThreadPoolExecutor(
                pool.getCoreSize(),
                pool.getMaxSize(),
                pool.getKeepAliveTime(),
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(100000),
                new ThreadFactoryBuilder()
                        .setNameFormat("Order-Thread-Pool-%d").build()
        );
    }
}
/**
 * yami.shop.name.not.blank=店铺名称不能为空
 * yami.shop.name.len.less=商品名称长度应该小于{max}
 * yami.shop.desc.len.less=店铺简介长度应该小于{max}
 * yami.shop.notice.len.less=店铺公告长度应该小于{max}
 * yami.shop.phone.not.blank=店铺联系电话不能为空
 * yami.shop.phone.len.less=店铺联系电话长度应该小于{max}
 * yami.shop.address.not.blank=店铺详细地址不能为空
 * yami.shop.address.len.less=店铺详细地址长度应该小于{max}
 * yami.shop.province.not.blank=店铺所在省份不能为空
 * yami.shop.province.len.less=店铺所在省份长度应该小于{max}
 * yami.shop.province.id.not.blank=店铺所在省份Id不能为空
 * yami.shop.city.not.blank=店铺所在城市不能为空
 * yami.shop.city.len.less=店铺所在城市长度应该小于{max}
 * yami.shop.city.id.not.blank=店铺所在城市Id不能为空
 * yami.shop.area.not.blank=店铺所在区域不能为空
 * yami.shop.area.len.less=店铺所在区域长度应该小于{max}
 * yami.shop.area.id.not.blank=店铺所在区域Id不能为空
 * yami.shop.logo.not.blank=店铺logo不能为空
 * yami.shop.logo.len.less=店铺logo长度应该小于{max}
 * yami.shop.photo.album.len.less=店铺相册长度应该小于{max}
 * yami.business.license.len.less=营业执照长度应该小于{max}
 * yami.id.front.len.less=身份证正面长度应该小于{max}
 * yami.id.negative.len.less=身份证反面长度应该小于{max}
 * yami.latitude.not.blank=店铺所在纬度不能为空
 * yami.longitude.not.blank=店铺所在经度不能为空
 * yami.distribution.cash.param1=提现金额不能为空
 * yami.distribution.cash.param2=最小提现金额为1元
 *
 *
 *
 *
 */
